﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TAP05
    {

        public TAP05()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAPARTK();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateAPARTK(dwMaster, 0);
            string key = KEY;
            KEY = "";
            KEY = key;
            base.OnSave();
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 15)
                return;
            dwData = TMV.TBMain.NewRow();
            dwData["APAKMANDANT"] = app.Mandant;
            dwData["APAKANRKRS"] = " AND APAKANRKRS='" + ORDERNUM.Substring(0, 2) + "'";
            dwData["APAKALFDNR"] = " AND APAKALFDNR='" + ORDERNUM.Substring(2, 6) + "'";
            dwData["APAKAFOLGE"] = " AND APAKAFOLGE='" + ORDERNUM.Substring(8, 3) + "'";
            dwData["APAKAEVOR"] = " AND APAKAEVOR='" + ORDERNUM.Substring(11, 4) + "'";
            SResult = TMV.QAPL04(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (EXAUF.Length < 11)
                return;
            dwData = TMV.TBMain.NewRow();
            dwData["APAKMANDANT"] = app.Mandant;
            dwData["APAKANRKRS"] = " AND APAKANRKRS='" + EXAUF.Substring(0, 2) + "'";
            dwData["APAKALFDNR"] = " AND APAKALFDNR='" + EXAUF.Substring(2, 6) + "'";
            dwData["APAKAFOLGE"] = " AND APAKAFOLGE='" + EXAUF.Substring(8, 3) + "'"; 
            SResult = TMV.QAPL04(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        }

    }
}
